package com.zhongzhi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhongzhi.service.AisleService;
import com.zhongzhi.service.EquipmentService;
import com.zhongzhi.springboot.pojo.Aisle;
import com.zhongzhi.springboot.pojo.Bo;
import com.zhongzhi.springboot.pojo.Equipment;
import com.zhongzhi.springboot.pojo.JsonResult;
/**
 * 设备业务层
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/equipment/")
public class EquipmentController {
	

	
	@Autowired
	private EquipmentService equipmentService;
	
	//1:增加设备
	@RequestMapping("insert")
	public JsonResult insert(Equipment equipment) {
		//System.out.println(equipment);//测试
		Bo bo = equipmentService.insert(equipment);
		if(bo.isBool()) {
			//插入数据返回id
			return new JsonResult(200,"新增设备成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"新增设备失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//2:修改设备
	@RequestMapping("update")
	public JsonResult update(Equipment equipment) {
		Bo bo = equipmentService.update(equipment);
		if(bo.isBool()) {
			return new JsonResult(200,"修改设备成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"修改设备失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	
	//3:删除设备(如果设备有者通道,则不能删除)
	@RequestMapping("delete")
	public JsonResult delete(Integer id) {
		Bo bo = equipmentService.delete(id);
		if(bo.isBool()) {
			return new JsonResult(200,"删除设备成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"删除设备失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//4:查询全部设备
	@RequestMapping("select")
	public JsonResult select(Integer pages,Integer line) {
		Bo bo = equipmentService.select(pages,line);
		if(bo.isBool()) {
			return new JsonResult(200,"查询设备成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"查询设备失败: "+bo.getMessage(),bo.getSize(),bo.getObject());
		}
	}
	
	//5:查询全部设备总数
			@RequestMapping("selectSize")
			public JsonResult selectSize() {
				Bo bo = equipmentService.selectSize();
				if(bo.isBool()) {
					return new JsonResult(200,"查询机型数量成功",bo.getSize(),bo.getObject());
				}else {
					return new JsonResult(500,"查询机型数量失败: "+bo.getMessage(),bo.getSize(),null);
				}
			}
	//6:查询设备(根据id查询)
	@RequestMapping("selectById")
	public JsonResult selectById(Integer id) {
		Bo bo = equipmentService.selectById(id);
		if(bo.isBool()) {
			return new JsonResult(200,"查询设备成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"查询设备失败: "+bo.getMessage(),bo.getSize(),bo.getObject());
		}
	}
}
